import 'dart:convert';

class DeviceModel {
  String id;
  int createdTime;
  Null creator;
  int modifiedTime;
  Null modifier;
  String name;
  Map nameMap;
  String storeId;
  String enterpriseId;
  bool display;
  String key;
  String args;
  String sn;
  bool online;
  String url;
  String ip;
  String relayHost;
  int relayPort;
  String loginKey;
  List<Channel> channel;
  int capability;
  List<String> capabilityList;
  String manufacturerCode;
  String position;
  List<HotspotBgImg> hotspotBgImg;
  String userId;
  String deviceArea;
  Null mediaSource;
  int lastOnlineTime;
  String type;
  String softVersion;
  String uuid;

  DeviceModel(
      {this.id,
      this.createdTime,
      this.creator,
      this.modifiedTime,
      this.modifier,
      this.name,
      this.nameMap,
      this.storeId,
      this.enterpriseId,
      this.display,
      this.key,
      this.args,
      this.sn,
      this.online,
      this.url,
      this.ip,
      this.relayHost,
      this.relayPort,
      this.loginKey,
      this.channel,
      this.capability,
      this.capabilityList,
      this.manufacturerCode,
      this.position,
      this.hotspotBgImg,
      this.userId,
      this.deviceArea,
      this.mediaSource,
      this.lastOnlineTime,
      this.type,
      this.softVersion,
      this.uuid});

  DeviceModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    createdTime = json['createdTime'];
    creator = json['creator'];
    modifiedTime = json['modifiedTime'];
    modifier = json['modifier'];
    name = json['name'];
    nameMap = json['nameMap'];
    storeId = json['storeId'];
    enterpriseId = json['enterpriseId'];
    display = json['display'];
    key = json['key'];
    args = json['args'];
    sn = json['sn'];
    online = json['online'];
    url = json['url'];
    ip = json['ip'];
    relayHost = json['relayHost'];
    relayPort = json['relayPort'];
    loginKey = json['loginKey'];
    if (json['channel'] != null) {
      channel = new List<Channel>();
      json['channel'].forEach((v) {
        channel.add(new Channel.fromJson(v));
      });
    }
    capability = json['capability'];
    capabilityList = json['capabilityList'].cast<String>();
    manufacturerCode = json['manufacturerCode'];
    position = json['position'];
    hotspotBgImg = json['hotspotBgImg'] == null ? null : List<HotspotBgImg>.from(json['hotspotBgImg'].map((x) => HotspotBgImg.frmJson(x)));
    userId = json['userId'];
    deviceArea = json['deviceArea'];
    mediaSource = json['mediaSource'];
    lastOnlineTime = json['lastOnlineTime'];
    type = json['type'];
    softVersion = json['softVersion'];
    uuid = json['uuid'];
  }
}

class Channel {
  int chnno;
  String name;
  bool online;
  String ip;
  bool hotspot;

  Channel({this.chnno, this.name, this.online, this.ip, this.hotspot});

  Channel.fromJson(Map<String, dynamic> json) {
    chnno = json['chnno'];
    name = json['name'];
    online = json['online'] == 0 ? false : true;
    ip = json['ip'];
    hotspot = json['hotspot'] == null ? false : json['hotspot'];
  }
}

class HotspotBgImg {
    int channel;
    String imageKey;
    String imageUrl;
    double width;
    double height;

    HotspotBgImg({
      this.channel,
      this.imageKey,
      this.imageUrl,
      this.width,
      this.height
    });

    HotspotBgImg.frmJson(Map<String, dynamic> json) {
      channel = json['channel'];
      imageKey = json['imageKey'];
      imageUrl = json['imageUrl'];
      width = json['width'] == null ? 0.0 : json['width'].toDouble();
      height = json['height'] == null ? 0.0 : json['height'].toDouble();
    }
  }

